const http = require('http');
const {fstat} = require('fs');
http.createServer((request,response)=>{
    const {url,method} = request;
    if(url==='/'&&method==='GET'){

        fstat.readFile('./index.html',(err,data)=>{
            if(err){
                response.writeHead(500,{
                    'Content-type':'text/plain;charset=utf-8'
                })

                response.end('500 服务器不行了')
                return
            }
            response.statusCode = 200;
            response.setHeader('Content-Type','text/html');
            response.end(data);
        })
    }else{
        response.statusCode = 400;
        response.setHeader('Content-Type','text/plain;charset=utf-8');
        response.end('404 翻遍了也没找到')
    }
})
.listen(3000,()=>{
    console.log('Server at 3000');
})